// src/utils/routers.js
const { createClient } = require('redis');

// 从文件中读取 Redis 配置
const redisHost = '47.96.91.185';
const redisPort = 6379 ;
const redisPassword = "meter@aly";

// 创建 Redis 客户端
const client = createClient({
    socket: {
        host: redisHost,
        port: redisPort
    },
    password: redisPassword
});

// 监听 Redis 连接事件
client.on('connect', () => {
    console.log('连接到 Redis');
});

client.on('error', (err) => {
    console.error('Redis 错误:', err);
});

// 确保在使用客户端之前连接
(async () => {
    try {
        await client.connect();
    } catch (err) {
        console.error('连接到 Redis 错误:', err);
    }
})();

module.exports = client;